import { dashboardGadgetList, defaultGadgetSettingList } from '@/utils/data-json'

export const useTransform = (type, fields = [], settings = {}) => {
  const setting = defaultGadgetSettingList.find(item => item.gadgetType === type)

  if (!setting) {
    console.warn('no setting')
    return () => ({})
  }

  if (typeof setting.transform !== 'function') {
    return () => ({})
  }

  return setting.transform(fields, settings)
}

export const useWidgetType = () => {
  return dashboardGadgetList.filter(item => (item.key === 'pvtablegadget' || item.key === 'cardnumbergadget' || item.key==='gridgadget' || item.key === 'processgaugegadget' || item.key === 'charthourglassgadget' || item.key === 'heatmapgadget' || item.key === 'barchartgadget' || item.key === 'chartgadget' || item.key === 'piechartgadget') && item.type === 'widget')
    .map(item => ({
      label: item.title,
      value: item.key,
      icon:item.imageUrl
    }))
}

